<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@ include file="/web/header.jsp" %>
<title>Insert title here</title>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin:10px;padding:15px">
	<legend>图片维护</legend>
	<div class="layui-field-box">
		<button type="button" class="layui-btn" id = "test1">
			<i class="layui-icon layui-icon-upload"></i>上传图片
		</button>
		<div class="layui-upload-list">
			<table class="layui-table">
				<thead>
					<tr>
						<th>文件名</th>
						<th>图片</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="demoList"></tbody>
			</table>
		</div>
	</div>
</fieldset>
<script type="text/javascript">
var code = '<%=request.getParameter("code") %>'
renderUpload('test1',"/EmployeeUpload",{code:code},function(res,index,upload){
	console.log(res.code)
	if(res.code==1){
		layer.msg('上传成功')
		showpic(res.image)
	}else{
		layer.msg('上传失败')
	}
})
function showpic(image){
	var html='<tr>'
	+"<td>"+image+"</td>"
	+"<td><img src ='/temp/"+image+"' alt='"+image+"' class='layui-upload-img'></td>"
	+"<td><input type='button' value='删除' class='layui-btn' onclick='delpic()'</td>"
	+"<tr>"
	$("#demoList").html(html);
}
function delpic(){
	openConfirm(function(){
		ajax({code:code,action:'delpic'},'/employee','text',function(data){
			if(data==1){
				layer.msg('删除成功')
				init();
			}else{
				layer.msg('删除失败')
			}
		})
	},"是否删除该图片？")
}
init();
function init(){
	ajax({code:code,action:'get'},'/employee','json',function(data){
		var image = data.image;
		if(image){
			showpic(res.image)
		}else{
			$("#demoList").html('');
		}
	}
}
</script>
</body>
</html>